package guiElements;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Scanner;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class ResultsCriteriaPanel extends JPanel {
	
	private ArrayList<String> colorsSelected, patternsSelected, wordsSelected;
	private JPanel keyWords, colorsSelectedPanel, patternsSelectedPanel;
	private JLabel keyWordsLabel, colorsSelectedLabel, patternsSelectedLabel;
	private Color buttonG, fontColor;
	private JButton returnButton;
	private FlowLayout customLayout;
	
	ResultsCriteriaPanel(){
		colorsSelected = null; patternsSelected = null; wordsSelected = null;
		setLayout(null);
		setBackground(Color.white);
		
		customLayout = new FlowLayout();
		customLayout.setVgap(0);
		
		keyWords = new JPanel();
		keyWords.setLayout(customLayout);
		keyWords.setBackground(Color.white);
		keyWords.setSize(new Dimension(90,100));
		keyWords.setLocation(new Point(0,0));
		keyWordsLabel = new JLabel("Name:");
		keyWordsLabel.setFont(new Font("Georgia", Font.PLAIN, 14));
		keyWordsLabel.setSize(new Dimension(90,25));
		keyWords.add(keyWordsLabel);
		add(keyWords);
		
		colorsSelectedPanel = new JPanel();
		colorsSelectedPanel.setLayout(customLayout);
		colorsSelectedPanel.setBackground(Color.white);
		colorsSelectedPanel.setSize(new Dimension(90, 250));
		colorsSelectedPanel.setLocation(new Point(0,100));
		colorsSelectedLabel = new JLabel("Colors:");
		colorsSelectedLabel.setFont(new Font("Georgia", Font.PLAIN, 14));
		colorsSelectedLabel.setSize(new Dimension(90, 25));
		colorsSelectedPanel.add(colorsSelectedLabel);
		add(colorsSelectedPanel);
		
		patternsSelectedPanel = new JPanel();
		patternsSelectedPanel.setLayout(customLayout);
		patternsSelectedPanel.setBackground(Color.white);
		patternsSelectedPanel.setSize(new Dimension(90, 205));
		patternsSelectedPanel.setLocation(new Point(0,350));
		patternsSelectedLabel = new JLabel("Patterns:");
		patternsSelectedLabel.setFont(new Font("Georgia", Font.PLAIN, 14));
		patternsSelectedLabel.setSize(new Dimension(90, 25));
		patternsSelectedPanel.add(patternsSelectedLabel);
		add(patternsSelectedPanel);
		
		returnButton = new JButton("<html> Return<br> to Search <html>");
		returnButton.setFont(new Font("Georgia", Font.PLAIN, 12));
		returnButton.setBackground(Color.darkGray);
		returnButton.setForeground(Color.white);
		returnButton.setSize(new Dimension(70,40));
		returnButton.setLocation(new Point(10, 555));
		add(returnButton);
		
	}

	public void updateCriteria(String nameText, ArrayList<String> colorsSelected, ArrayList<String> patternsSelected){
		this.colorsSelected = colorsSelected;
		this.patternsSelected = patternsSelected;
		wordsSelected = new ArrayList<String>(0);
		Scanner scan = new Scanner(nameText);
		scan.useDelimiter(" ");
		while(scan.hasNext()){
			wordsSelected.add(scan.next());
		}
		scan.close();
		
		
		keyWords.removeAll();
		keyWords.add(keyWordsLabel);		
		colorsSelectedPanel.removeAll();
		colorsSelectedPanel.add(colorsSelectedLabel);
		patternsSelectedPanel.removeAll();
		patternsSelectedPanel.add(patternsSelectedLabel);
		
		
		for (String wurd : wordsSelected){
			JLabel wordLabel = new JLabel(wurd, JLabel.CENTER);
			wordLabel.setPreferredSize(new Dimension(90,15));
			wordLabel.setBackground(Color.white);
			wordLabel.setForeground(Color.black);
			keyWords.add(wordLabel);
		}
		
		
		for(String colur : colorsSelected ){
			JLabel colorNameLabel = new JLabel(colur);
			colorNameLabel.setOpaque(true);
			colorNameLabel.setPreferredSize(new Dimension(90,15));
			Color compColor = new Color(150,150,150);
			switch(colur.toLowerCase()){
			
			case "multiple":
				buttonG = new Color(200,200,200);
				break;		
			case "black":
				buttonG = new Color(0,0,0);
				break;
			case "blue":
				buttonG = new Color(0,0,255);
				break;
			case "brown":
				buttonG = new Color(69,51,18);
				break;
			case "burgundy":
				buttonG = new Color(112,11,47);
				break;
			case "gold":
				buttonG = new Color(227, 195,16);
				break;
			case "green":
				buttonG = new Color(0,220,0);
				break;
			case "orange":
				buttonG = new Color(252,144,3);
				break;
			case "pink":
				buttonG = new Color(242,107,177);
				break;
			case "purple":
				buttonG = new Color(115,19,133);
				break;
			case "red":
				buttonG = new Color(255,0,0);
				break;
			case "silver":
				buttonG = new Color(180,180,180);
				break;
			case "tan":
				buttonG = new Color(209,179,113);
				break;
			case "white":
				buttonG = new Color(255,255,255);
				break;
			case "yellow":
				buttonG = new Color(255,255,80);
				break;
			}
			if(buttonG.getRGB()>compColor.getRGB()){
				fontColor = Color.black;
			}
			else { 
				fontColor = Color.white;
			}
			colorNameLabel.setBackground(buttonG);
			colorNameLabel.setForeground(fontColor);
			colorsSelectedPanel.add(colorNameLabel);
		}
			
		for(String patturn : patternsSelected){
			JLabel patternNameLabel = new JLabel(patturn);
			patternNameLabel.setPreferredSize(new Dimension(90,15));
			patternNameLabel.setBackground(Color.white);
			patternNameLabel.setForeground(Color.black);
			patternsSelectedPanel.add(patternNameLabel);
		}	
		
	}

	public ArrayList<String> getColorsSelected() {
		return colorsSelected;
	}

	public void setColorsSelected(ArrayList<String> colorsSelected) {
		this.colorsSelected = colorsSelected;
	}

	public ArrayList<String> getPatternsSelected() {
		return patternsSelected;
	}

	public void setPatternsSelected(ArrayList<String> patternsSelected) {
		this.patternsSelected = patternsSelected;
	}

	public JPanel getKeyWords() {
		return keyWords;
	}

	public void setKeyWords(JPanel keyWords) {
		this.keyWords = keyWords;
	}

	public JPanel getColorsSelectedPanel() {
		return colorsSelectedPanel;
	}

	public void setColorsSelectedPanel(JPanel colorsSelectedPanel) {
		this.colorsSelectedPanel = colorsSelectedPanel;
	}

	public JPanel getPatternsSelectedPanel() {
		return patternsSelectedPanel;
	}

	public void setPatternsSelectedPanel(JPanel patternsSelectedPanel) {
		this.patternsSelectedPanel = patternsSelectedPanel;
	}

	public JButton getReturnButton() {
		return returnButton;
	}

	public void setReturnButton(JButton returnButton) {
		this.returnButton = returnButton;
	}
	
	
}
